package com.ra.landlord;

import java.io.Serializable;

import com.googlecode.cswish.struts.spring.GenericService;
import com.googlecode.cswish.struts.spring.ObjectFactory;
import com.ra.weixin.WeixinUser;


/**
 * 存储用户的扩展信息
 * 
 * @author Jerry
 *
 */
public class UserExtContext implements Serializable {
	
	private static final long serialVersionUID = 1L;

	private Integer landlordUserId;
	private transient LandlordUser landlordUser;
	
	private Integer weixinUserId;
	private transient WeixinUser weixinUser;
	
	public Integer getLandlordUserId() {
		return landlordUserId;
	}

	public Integer getWeixinUserId() {
		return weixinUserId;
	}

	public LandlordUser loadLandlordUser() {
		if (landlordUser == null && landlordUserId != null) {
			landlordUser = ObjectFactory.getInstance().getBean(GenericService.class, false)
					.load(LandlordUser.class, landlordUserId);
		}
		return landlordUser;
	}

	public void setLandlordUser(LandlordUser landlordUser) {
		this.landlordUser = landlordUser;
		this.landlordUserId = landlordUser.getId();
	}
	
	public WeixinUser loadWeixinUser() {
		if (weixinUser == null && weixinUserId != null) {
			weixinUser = ObjectFactory.getInstance().getBean(GenericService.class, false)
					.load(WeixinUser.class, weixinUserId);
		}
		return weixinUser;
	}

	public void setWeixinUser(WeixinUser weixinUser) {
		this.weixinUser = weixinUser;
		this.weixinUserId = weixinUser.getId();
	}

	public boolean hasUserInfo() {
		return landlordUserId != null || weixinUser != null;
	}
	
	public LandlordOwnerUser getOwnerUser() {
		if (landlordUserId != null) {
			return loadLandlordUser().getOwnerUser();
		} else {
			return null;
		}
	}
}